#include <Polygon.hpp>

Modeling::Polygon::~Polygon()
{
	for (unsigned int i=0 ; i<this->getNormalsQty() ; i++)
		delete this->normal[i];
}

Modeling::Polygon::Polygon()
{}

Modeling::Polygon::Polygon(Vector3f* v1, Vector3f* v2, Vector3f* v3)
{
	this->addVertex(v1);
	this->addVertex(v2);
	this->addVertex(v3);

	this->addNormal( this->getPolygonNormal() );
	this->addNormal( this->getPolygonNormal() );
	this->addNormal( this->getPolygonNormal() );

}

unsigned int Modeling::Polygon::getVertQty()
{
	return this->vertex.size();
}

void Modeling::Polygon::addVertex(Vector3f* vertex)
{
	this->vertex.push_back(vertex);
}

Vector3f* Modeling::Polygon::getVertex(unsigned int index)
{
	return this->vertex[index];
}

Vector3f Modeling::Polygon::getPolygonNormal()
{
	Vector3f v0 = *this->getVertex(0);
	Vector3f v1 = *this->getVertex(1);
	Vector3f v2 = *this->getVertex(2);

	Vector3f V1 = v1 - v0;
	Vector3f V2 = v2 - v0;

	return (V1*V2).normalized(); 
	
}

unsigned int Modeling::Polygon::getNormalsQty()
{
	return this->normal.size();
}

void Modeling::Polygon::addNormal(Vector3f normal)
{
	Vector3f* norm = new Vector3f(normal);
	this->normal.push_back(norm);
}

Vector3f* Modeling::Polygon::getNormal(unsigned int index)
{
	return this->normal[index];
}

unsigned int Modeling::Polygon::getMapCoordsQty()
{
	return this->mapCoord.size();
}

void Modeling::Polygon::addMapCoord(Vector2f* mapCoord)
{
	this->mapCoord.push_back(mapCoord);
}

Vector2f* Modeling::Polygon::getMapCoord(unsigned int index)
{
	return this->mapCoord[index];
}

Modeling::Material* Modeling::Polygon::getMaterial()
{
	return this->material;
}

void Modeling::Polygon::setMaterial(Modeling::Material* material)
{
	this->material = material;
}
